<script language="javascript">
	function showtheoloai(id,d,name)
	{
		//document.dstintuc.value_radio.value=d.value;
		showdataday(id,'admin/showloaitintuc.php?' +name + '=' + d.value);
	}
</script>
	<form name="dstintuc" method="post" action="home_admin.php">
		<div>
			<?php
				$loai=$_GET['loai'];
				/*if($loai==0)
					$message="<input name='loaitintuc' type='radio' value='1' onclick='showtheoloai('id_loaitin',this)' />&nbsp;TIN XÃ HỘI&nbsp;&nbsp;&nbsp;<input type='radio' checked='checked' value='0' name='loaitintuc' onclick='showtheoloai('id_loaitin',this)' />&nbsp;TIN NỘI BỘ";
				else
					$message="<input name='loaitintuc' type='radio' onclick='showtheoloai('id_loaitin',this)' checked='checked' value='1' />&nbsp;TIN XÃ HỘI&nbsp;&nbsp;&nbsp;<input type='radio' value='0' onclick='showtheoloai('id_loaitin',this)' name='loaitintuc' />&nbsp;TIN NỘI BỘ";*/
				$k=$knoi->queryCsdl("select maloaitt,tenloai from loaitintuc where loai='$loai' limit 0,1");
				$t=mysql_fetch_array($k);
				$madt=$t['maloaitt'];
				$k=$knoi->queryCsdl("select maloaitt,tenloai from loaitintuc where loai='$loai' and maloaitt!='$madt'");
			?>
		
			<p>
			<?php
				 if($loai==0)
				 {
			  ?>
			  		<input name="loaitintuc" type="radio" value="1" onclick="showtheoloai('id_loaitin',this,'loaitintuc')" />&nbsp;TIN XÃ HỘI&nbsp;&nbsp;&nbsp;<input type="radio" checked="checked" value="0" name="loaitintuc" onclick="showtheoloai('id_loaitin',this,'loaitintuc')" />&nbsp;TIN NỘI BỘ
			<?php
				}
				else
				{
			?>
					<input name="loaitintuc" type="radio" checked="checked" value="1" onclick="showtheoloai('id_loaitin',this,'loaitintuc')" />&nbsp;TIN XÃ HỘI&nbsp;&nbsp;&nbsp;<input type="radio"  value="0" name="loaitintuc" onclick="showtheoloai('id_loaitin',this,'loaitintuc')" />&nbsp;TIN NỘI BỘ
			<?php
				}
			?>
			</p>
			<div id="id_loaitin">
				<label class="stylelitle">Loại tin tức:</label>&nbsp;
				<select name="select" onchange="showtheoloai('id_tintuc',this,'maloai')">
                  <option selected="selected" value="<?php echo $madt; ?>"><?php echo $t['tenloai']; ?></option>
                  <?php
				while($n=mysql_fetch_array($k))
				{
			?>
                  <option value="<?php echo $n['maloaitt']; ?>"><?php echo $n['tenloai']; ?></option>
                  <?php
				}
			?>
                </select>
				<div id="id_tintuc" align="center">
			  <?php
					$d=$knoi->queryCsdl("select matt from tintuc where maloaitt='$madt'");
					if(mysql_num_rows($d)<1)
					{
						echo "<br><label class='stylelitle'>Hiện tại chưa có tin tức nào!</label><br>";
					}
					else
					{
					$tongdong=mysql_num_rows($d);
					$dong_trang=9;
					$sotrang=ceil($tongdong/$dong_trang);
					
					$limit="0,".$dong_trang;
					if(isset($_GET['page']))
					{
						$t=$_GET['page'];
						$ar=explode(":",$t);
						$limit=$ar[1];
					}
					//echo $limit;
					if($sotrang==1)
						$kq=$knoi->queryCsdl("select matt,tieude,ngaydang,trangthai from tintuc where maloaitt='$madt'");
					else
						$kq=$knoi->queryCsdl("select matt,tieude,ngaydang,trangthai from tintuc where maloaitt='$madt' limit $limit");
				?>
			  <table align="center" style="border:solid #FFFFFF; background-color:#F5F5F5">
						<tr class="stylelitle"  style="text-align:center; background-color:#CCFFFF"><td style="text-align:right">Stt&nbsp;</td><td style="text-align:center;">Tiêu đề</td><td>Ngày đăng</td><td>Trạng thái</td><td>Chi tiết</td><td>Xóa</td></tr>
					<?php
						$i=1;
						if(isset($_GET['i']))
							$i=$_GET['i'] + 1;
						while($n=mysql_fetch_array($kq))
						{
							if($i%2==0)
								$color='#FFFFCC';
							else
								$color='#FFFFFF';
					?>
						<tr  class="classtr" style="text-align:left; background-color:<?php echo $color; ?>;"><td align="right"><?php echo $i; ?>&nbsp;</td><td><?php echo $n['tieude']; ?></td>
						<td align="center">
						<?php 
							$date=$n['ngaydang'];
							//echo $date;
							$tam=explode(" ",$date);
							$date=$tam[0];
							//echo "<br>date0: ".$tam[1]."<br>";
							$date=$knoi->formatDate($date); 
							echo $date; 
							//echo "trangchu";
						?>						</td>
						<td align="center"><?php if($n['trangthai']==0) echo "Lưu"; else echo "Đăng"; ?></td><td style="text-align:center"><a  href="home_admin.php?module=chitiettintuc&matt=<?php echo $n['matt']; ?>"><img src="images/chitiet.png" border="0" title="Chi tiết loại tin tức" /></a></td>
						<td style="text-align:center;"><a href="home_admin.php?module=xoa&field=matt&table=tintuc&value=<?php echo $n['matt']; ?>"><img src="images/Sign-Error-icon1.png" border="0" title="Xóa tin tức" /></a></td></tr>
					<?php
						$i++;
						}
					?>
			  </table>
				<?php
					}
			if($sotrang>1)
			{
		 	if($ar[0]!=1 && isset($_GET['page']))
				$color='#0033CC';
			else
				$color='#000000';
			$start="1:0,".$dong_trang;
			?>
			<div> Pages &nbsp;
			<?php
				echo "<a href='home_admin.php?module=danhsachtintuc&loai=$loai&page=$start' style='color:$color'>1</a>";
			for($i=2;$i<=$sotrang;$i++)
			{
				if($ar[0]==$i)
					$color='#000000';
				else
					$color='#0033CC';
				$p=($i-1)*$dong_trang;
				$page=$i.":".$p.",".$dong_trang;
				echo "&nbsp;<a href='home_admin.php?module=danhsachtintuc&loai=$loai&page=$page&i=$p' style='color:$color'>$i</a>";	
			}
			?>
			</div>
			<?php
			}
		  ?>
			<br /><label style="text-align:center" class="button"><a class="menulink" href="home_admin.php?module=tintuc&loai=<?php echo $loai; ?>&loaitin=<?php echo $madt; ?>"><img src="images/add.png" border="0">&nbsp;Tin tức mới</a></label>
			 </div>
		</div>
		</div>
</form>
